package divtastic.js;

import js.Lib;
import divtastic.js.DisplayDiv;

enum BrowserType
{
    WebKit;
    Mozilla;
    Opera;
    IE;
}

class Browser
{
    
    private static var _browserType:   BrowserType;
    public static var browserType( get_BrowserType, null ): BrowserType;
    
    
    public static function addChild( d: Dynamic, mc: DisplayDiv ):Void
    {
        
        Lib.document.body.appendChild( mc.getInstance() );
        
    }
    
    public static function get_BrowserType(): BrowserType
    {
        
        if( _browserType == null )
        {
            
            setBrowserType( Lib.window.navigator.userAgent );
            
        }
        
        return _browserType;
        
    }
    
    public static function setBrowserType( agent: String ): BrowserType
    {
        
        if( (~/WebKit/).match( agent ) )
        {
            _browserType = WebKit;
        }
        else if( (~/Opera/).match( agent ) )
        {
            
            _browserType = Opera;
            
        }
        else if( (~/Mozilla/).match( agent ) )
        { 
            _browserType = Mozilla;
        }
        else
        {
            _browserType = IE;
        }
        
        return _browserType;
        
    }
    
}